/**
* Copyright (c) By zengqh.
*
* This program is just for fun or demo, in the hope that it  
* will be useful, you can redistribute it and/or modify freely.
*
* Time: 2013/03/16
* File: MeshFile.h
* Blog: http://www.cnblogs.com/zengqh/
**/

#pragma once

namespace HY
{
class MeshFile
{
public:
	static const uint32 MAGIC							= 0x57754631;
	static const uint32 VERSION							= 2;

	/** chunk type. */
	static const uint32 CHUNK_MESHFILE					= 0x00000001;
	static const uint32 CHUNK_MATERIALS					= 0x00000010;
	static const uint32 CHUNK_MESH						= 0x00000011;
	static const uint32 CHUNK_LODLEVEL					= 0x00000012;
	static const uint32 CHUNK_INDEXBUFFER				= 0x00000013;
	static const uint32 CHUNK_GEOMETRY					= 0x00000014;
	static const uint32 CHUNK_MORPHTARGET				= 0x00000015;
	static const uint32 CHUNK_VERTEXBUFFER				= 0x00000016;
	static const uint32 CHUNK_VERTEXATTRIBUTE			= 0x00000017;
	static const uint32 CHUNK_WEIGHT					= 0x00000018;
	static const uint32 CHUNK_VERTEXWEIGHTS				= 0x00000019;
	static const uint32 CHUNK_SKELETON					= 0x00000020;
	static const uint32 CHUNK_SKELETONANIMATION			= 0x00000021;
	static const uint32 CHUNK_ANCHORPOINTS				= 0x00000022;
	static const uint32 CHUNK_ANIMATIONS				= 0x00000023;
	static const uint32 CHUNK_MORPHTARGETANIMATION		= 0x00000024;
	static const uint32 CHUNK_MESHBOUNDINGBOX			= 0x00000025;

public:
	struct Chunk
	{
		uint32 type;
		uint32 size;
	};

	struct MeshFileHeader
	{
		uint32 magic;
		uint32 version;
	};

	struct Materials
	{
		uint32 mat_num;
	};

	struct Mesh
	{
		uint32 lod_levels;
		uint32 morph_targets;
		uint32 weights;
		uint32 vertex_weights;
	};

	struct BoundingBox
	{
		float vmin[3];
		float vmax[3];
	};

	struct Weight
	{
		int nJoint;
		float bias;
	};

	struct VertexWeight
	{
		uint32 nWeights;
	};

	struct LODLevel
	{
		float			distance;
		uint32			nGeo;
		uint32			nOctreeSubdivide;
		uint32			nOctreeMinGeometries;
	}

	struct IndexBuffer
	{
		uint32		elem_type;
		uint32		elems;
		uint32		size;
	};

	struct Geometry
	{
		char		name[64];
		uint32		flags;
		bool		active;
		int			prim_type;
		int			nMat;
		int			start_idx;
		int			idx_size;
	};

	struct MorphTarget
	{
		char		name[64];
		bool		is_relative;
		uint32		vertex_id;
		uint32		vertex_buffer;
	};

	struct VertexBuffer
	{
		uint32		vertex_attr;
		uint32		vertices;
		uint32		size;
	};

	struct VertexAttribute
	{
		int semantic;
		int channel;
		int type;
	};

	struct MorphTargetAnimation
	{
		char		name[64];
		uint32		morph_targets;
		uint32		frames;
	};

	struct Skeleton
	{
		char		name[64];
		uint32		joints;
		uint32		frames;
	};

	struct Joint
	{
		char		name[64];
		int			parent;
		uint8		anim_components;
	};

	struct JointState
	{
		float	translation[3];
		float	rotation[4];
		float	translation_joint_space[3];
		float	rotation_joint_space[4];
	};

	struct AnchorPoints
	{
		uint32 anchor_points;
	};

	struct AnchorPoint
	{
		char		name[64];
		bool		bType;
		int			id;
	};

	struct Animations
	{
		uint32 animations;
	};

	struct Animation
	{
		char		name[64];
		int			type;
		int			start;
		int			end;
		float		speed;
		uint32		flags;
		int			nEvents;
	};

	struct AnimationFrame
	{
		float speed;
	};

	struct AnimationEvent 
	{
		int		id;
		int		nFrame;
	};
};
}